
def call(Map config){

    pipeline {
        agent any
        environment { //设置环境变量 与Jenkinsfile对应
            ipList = "${config.IPS}"
            credentials_id = "${config.CREID}"
            git_url = "${config.GITURL}"
            mvn_param = "${config.MVN_PARAM}"
            mvn_package_param = "${config.MVN_PACK_PARAM}"
            service_name = "${config.SERVICE_NAME}"
            project_name = "${config.PROJECT_NAME}"
            default_branch = "${config.DEFAULT_BRANCH}"
        }

        parameters {
            gitParameter (
                    defaultValue: default_branch,
                    branchFilter: 'origin/(.*)',
                    name: 'BRANCH',
                    quickFilterEnabled: true,
                    selectedValue: 'DEFAULT',
                    sortMode: 'DESCENDING_SMART',
                    tagFilter: '*',
                    type: 'PT_BRANCH',
                    description: 'Please select a branch or tag to build',
                    useRepository: git_url
            )
        }

        stages{
            stage('Build') {
                steps{
                    git  branch:  params.BRANCH, changelog: false, credentialsId:credentials_id , poll: false, url: git_url
                    sh "mvn clean -P ${mvn_param}  ${mvn_package_param} -Dmaven.test.skip=true"
                }

                post {
                    success {
                        archiveArtifacts 'target/*.jar'
                    }
                }
            }

            stage('Deploy') {
                steps {
                    //发布项目  参考之前的文章
                    //构建失败终止计划
                    if('FAILURE'.equals(currentBuild.result) || 'UNSTABLE'.equals(currentBuild.result)) {
                        echo "Current build is in FAILURE or UNSTABLE state, the whole process will exit!!"
                        break;
                    }
                }
            }
        }
    }
}